class Idris2 < Formula
  desc "Pure functional programming language with dependent types"
  homepage "https://www.idris-lang.org/"
  url "https://github.com/idris-lang/Idris2/archive/v0.2.0.tar.gz"
  sha256 "cc7c48d3fbaa55e536890c9eb4701755081d2b5df9a65f0ecc3e00ee5ccf0a0f"

  bottle do
    cellar :any
    sha256 "23d5a50ddc93380262ba3a921ccb6b41fcf83647158d8b4a4042fd76a7fe2496" => :catalina
    sha256 "67548c580e290130ae9dfb5188fcda51417ff9e94e52ca331daa63252288fd5c" => :mojave
    sha256 "c91f5057e6803de074590918078092f3dcb2dbf0ed07fb97db5633b03b8405fc" => :high_sierra
  end

  depends_on "coreutils" => :build
  depends_on "chezscheme"

  def install
    ENV.deparallelize
    scheme = Formula["chezscheme"].bin/"chez"
    system "make", "bootstrap", "SCHEME=#{scheme}", "PREFIX=#{libexec}"
    system "make", "install", "PREFIX=#{libexec}"
    # idris2.so is an executable file generated by Idris2
    bin.install "#{libexec}/bin/idris2_app/idris2.so" => "idris2"
    lib.install_symlink Dir["#{libexec}/lib/*.dylib"]
  end

  test do
    (testpath/"hello.idr").write <<~EOS
      module Main
      main : IO ()
      main = putStrLn "Hello, Homebrew!"
    EOS

    system bin/"idris2", "hello.idr", "-o", "hello"
    assert_equal "Hello, Homebrew!",
                 shell_output("./build/exec/hello_app/hello.so").chomp
  end
end
